/**
 * Created by CZ on 2017/4/6.
 */
module.exports = function ($scope,$rootScope,$interval,$state,RequestService,commonConfig,modelService,$localStorage) {
    //获取token
    var token = $localStorage.get('cloud').token;
    // //获取验证码
    // $scope.img = commonConfig.$webroot+commonConfig.userApi+'user/user/getVerifyImage?access_token='+token;
    // //获取验证码图片
    // $scope.getVerifyCode = function(){
    //     var time = new Date().getTime();
    //     $scope.img = commonConfig.$webroot+commonConfig.userApi+'user/user/getVerifyImage?'+time+'&access_token='+token;
    // };
    $scope.form = {
        identityNumber:'',
        verifyCode:'',
        password:'',
        newPassword:''

    };
    $scope.submitPsw = function(){  //提交密码
        var data ={
            identityNumber:$scope.form.identityNumber,
            verifyCode:$scope.form.verifyCode,
            newPassword:$scope.form.newPassword
        };
        RequestService.Request(commonConfig.userApi+'user/user/changePasswordByIdentityNumber','POST',data).then(function(response){
            console.log(response);
            if(response.code == 0){
                //修改成功并跳转至登录页面
                modelService.openTipsModel('密码重置成功！','CloudPlatform.home');
            }else {  //code = 200
                modelService.openTipsModel('密码重置失败！');
            }
        },function(error){
            console.log(error);
        });

    };
    //获取图片验证码
    $scope.getVerifyImage = function(){
        RequestService.Request(commonConfig.userApi+'user/verifyimage/getVerifyImage', 'GET').then(function(res){
            // console.log(res);
            $scope.imgKey = res[0];
            $scope.img = res[1];
        },function(error){
            console.log(error);
        });
    };
    $scope.getVerifyImage();
    //验证图片验证码
    $scope.ImageCodeVerifyResult = 0;
    $scope.VerifyImageCode = function(){
        var data = {
            "key": $scope.imgKey,
            "verifyCode": $scope.form.verifyCode
        };
        RequestService.Request(commonConfig.userApi+'user/verifyimage/verifyCode', 'POST',data).then(function(res){
            // console.log(res);
            $scope.ImageCodeVerifyResult = res.code;
        },function(error){
            console.log(error);
        });
    };
};